package com.dao;

import java.util.List;

import com.entity.City;
import com.util.Page;

public class CityDao extends BaseDAO {
	
	/**
	 * 保存城市
	 * @param city
	 * @return
	 */
	public boolean saveCity(City city){
		return this.saveObject(city);
	}
	
	/**
	 * 查询所有分类 
	 * @return
	 * @throws Exception
	 */
	public List<City> findCityList() throws Exception{
		return this.queryObject(City.class);
	}
	
	/**
	 * 查询单个对象
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public City editCity(String id) throws Exception{
		City City = null;
		City = (City) this.queryByObjectId(City.class, "where :id=?",id);
		return City;
	}	
	
	/**
	 * 删除多个商品分类
	 * @param ids
	 * @return
	 */
	public boolean delCitys(String ids){
		String sql = "delete from citys where id in ("+ids+")";
		return this.executeUpdate(sql);
	}
	/**
	 * 取一级菜单
	 * @return
	 * @throws Exception
	 */
	public List<City> findTopNod() throws Exception{
		String sql  = "select * from citys where parentid=0";
		return this.findObjectBySql(City.class, sql);
	}
	
	/**
	 * 取二级菜单
	 * @return
	 */
	public List<City> findTowNod(){
		String sql = " select * from citys where parentid  in (select id from citys where parentid=0)";
		return this.findObjectBySql(City.class, sql);
	}
	
	/**
	 * 取二级菜单
	 * @return
	 * @throws Exception 
	 */
	public List<City> findParentCityById(int id) throws Exception{
		return this.queryObject(City.class,"where parentid=?",id);
	}
	
	/**
	 * 取三级菜单
	 * @return
	 */
	public List<City> findThreeNod(){
		String sql = " select * from citys where parentid  in (select id from citys where parentid  in (select id from citys where parentid=0))";
		return this.findObjectBySql(City.class, sql);
	}
	
	public boolean delCity(){
		return false;
	}
	
	public boolean updateCity(String sql){
		return this.executeUpdate(sql);
	}
	
	public boolean delGtypeById(){
		return false;
	}

	/**
	 * 按分页查询
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public Page findbyPage(Page page) throws Exception{
		return this.queryObjectForPage(City.class, page);
	}
}
